home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / xv_pc17.zip / XVTEST.C < prev   
C/C++ Source or Header  |  1994-08-03  |  11KB  |  393 lines

  1. /*
  2. Test program for the PC-XView interface in C/C++
  3. By Antonio Carlos Moreirao de Queiroz - acmq@coe.ufrj.br
  4. Version 1.0a - 19/04/94
  5. Version 1.1  - 09/07/94 - Simple bitmap editor; Compatible with djgpp
  6. Version 1.1a - 01/08/94 - No more measurements of memory used
  7.  
  8. To compile with Borland C:
  9.  
  10. Make a project with mickey.obj, xview.obj, and xvtest.c.
  11. Use Turbo C++ 1.0 or more recent version.
  12. Set the memory model to "huge".
  13. Set linking with floating point and graphics libraries.
  14. Set the environment variable TCBGI to where are the BGI drivers with the
  15. correct version (the ones in xv_pc*.zip are for Turbo Pascal 7.0).
  16. Set the environment variable BMP to where are the ".bmp" files.
  17. This is not necessary if the .bgi and .bmp files are in the current directory.
  18.  
  19. To compile with GNU C ("djgpp"):
  20. The necessary files are "mickey.o", "xview.o", and the corresponding .h
  21. files, that are not the same of the Borland C version.
  22. See the file "xview_pc.txt" for information on how to get these files.
  23. Set the environment variables in a way that works with the "libgrx"
  24. and "bcc2grx" packages for djgpp.
  25. Set the environment variable TCBGI to where is the "litt.chr" BGI font file.
  26. Set the environment variable BMP to where are the ".bmp" files.
  27. Compile the program with:
  28.   gcc -Wall mickey.o xview.o xvtest.c -lbcc -lgrx -lpc -lm -o xvtest
  29. Execute with "go32 xvtest", or use "strip xvtest" and "coff2exe xvtest" to
  30. produce a directly executable program.
  31. */
  32.  
  33. #include <stdio.h>
  34. #include <string.h>
  35. #include "xview.h"
  36. #include "notice.h"
  37.  
  38. #ifdef __GNUC__
  39. #include <DPMI.h>
  40. #define coreleft _go32_dpmi_remaining_virtual_memory
  41. #endif
  42.  
  43. #define PWIDTH 32
  44. #define PHEIGHT 32
  45.  
  46. int color=0;
  47. char buf[200];
  48. unsigned char painting[PWIDTH][PHEIGHT];
  49. int pwidth,pheight;
  50.  
  51. /* Declaration of the interface objects */
  52. Xv_opaque menu1,menu2;
  53. Xv_opaque frame1,tty1,button1,button2,button3,
  54.   button4,button5,text2,text3,text4,
  55.   button6;
  56. Xv_opaque frame2,canvas1,message1;
  57. Xv_opaque frame3,setting1,setting2,button7,message2;
  58.  
  59. void ClearPainting(void)
  60. {
  61.   int i,j;
  62.  
  63.   for (i=0;i<PWIDTH;i++)
  64.     for (j=0;j<PHEIGHT;j++)
  65.       painting[i][j]=15;
  66. }
  67.  
  68. /* Callback procedures */
  69.  
  70. void Open1(Xv_opaque obj)
  71. {
  72.   /* Notify handler for button1 */
  73.   open_window(frame2);
  74. }
  75.  
  76. void Open2(Xv_opaque obj)
  77. {
  78.   /* Notify handler for button2 */
  79.   open_window(frame3);
  80. }
  81.  
  82. void Quit(Xv_opaque obj)
  83. {
  84.   /* Notify handler for button3 */
  85.   xv_end=notice("Exit to DOS?");
  86. }
  87.  
  88. void Icon1(Xv_opaque obj)
  89. {
  90.   /* Notify handler for button4 */
  91.   ttysw_output(tty1,"XView-PC\r\nBy Antonio C. M. de Queiroz\r\n");
  92. }
  93.  
  94. void Icon2(Xv_opaque obj)
  95. {
  96.   /* Notify handler for button5 */
  97.   ttysw_output(tty1,"Federal University of\r\nRio de Janeiro, Brazil\r\n");
  98. }
  99.  
  100. void EnterText(Xv_opaque obj)
  101. {
  102.   /* Notify handler for text2 */
  103.   sprintf(buf,"Text: %s\r\n",obj->v.stextfield.panel_value);
  104.   ttysw_output(tty1,buf);
  105. }
  106.  
  107. void EnterInt(Xv_opaque obj)
  108. {
  109.   /* Notify handler for text3 */
  110.   sprintf(buf,"Integer: %d\r\n",obj->v.stextfield.panel_int);
  111.   ttysw_output(tty1,buf);
  112. }
  113.  
  114. void EnterReal(Xv_opaque obj)
  115. {
  116.   /* Notify handler for text4 */
  117.   sprintf(buf,"Real: %g\r\n",obj->v.stextfield.panel_real);
  118.   ttysw_output(tty1,buf);
  119. }
  120.  
  121. void Icon3(Xv_opaque obj)
  122. {
  123.   /* Notify handler for button6 */
  124.   ttysw_output(tty1,"E-mail: acmq@coe.ufrj.br\r\n");
  125. }
  126.  
  127. void Close2(Xv_opaque obj)
  128. {
  129.   /* Notify handler for frame2 and frame3 */
  130.   sprintf(buf,"Closed %s\r\n",obj->xv_label);
  131.   ttysw_output(tty1,buf);
  132. }
  133.  
  134. void ReDraw(Xv_opaque obj)
  135. {
  136.   /* Notify handler for canvas1 */
  137.   int i,j;
  138.  
  139.   /* Updates the pixel size and redraws the painting */
  140.   pwidth=canvas1->dx/PWIDTH;
  141.   pheight=canvas1->dy/PHEIGHT;
  142.   for (i=0;i<PWIDTH;i++)
  143.     for (j=0;j<PHEIGHT;j++) {
  144.       setfillstyle(SOLID_FILL,painting[i][j]);
  145.       bar((i*pwidth),(j*pheight),(i+1)*pwidth-1,(j+1)*pheight-1);
  146.     }
  147. }
  148.  
  149. void Draw(Xv_opaque obj)
  150. {
  151.   /* Event handler for canvas1 */
  152.   int i,j;
  153.  
  154.   /* Lists mouse location */
  155.   if (ie_code==LOC_MOVE) {
  156.     sprintf(buf,"x:%d y:%d",ie_locx,ie_locy);
  157.     xv_set(message1,buf);
  158.   }
  159.   /* Adds pixel to painting */
  160.   else if (ie_shiftcode==1) {
  161.     i=ie_locx/pwidth;
  162.     j=ie_locy/pheight;
  163.     setfillstyle(SOLID_FILL,color);
  164.     if ((i<PWIDTH) && (j<PHEIGHT)) {
  165.       bar((i*pwidth),(j*pheight),(i+1)*pwidth-1,(j+1)*pheight-1);
  166.       painting[i][j]=color;
  167.     }
  168.   }
  169. }
  170.  
  171. void ChangeColor(Xv_opaque obj)
  172. {
  173.   /* Notify handler for setting1 and setting2 */
  174.   /* Updates the color and makes the two settings agree */
  175.   if (obj==setting2) {
  176.     color=obj->v.ssetting.sel_setting;
  177.     setting1->v.ssetting.sel_setting=color+1;
  178.     draw_object(setting1,0);
  179.   }
  180.   else {
  181.     color=obj->v.ssetting.sel_setting-1;
  182.     setting2->v.ssetting.sel_setting=color;
  183.     draw_object(setting2,0);
  184.   }
  185.   /* Lists the color selection, with an example */
  186.   sprintf(buf,"Selection=%d\r\n",obj->v.ssetting.sel_setting);
  187.   ttysw_output(tty1,buf);
  188.   /* Shows the color */
  189.   message2->fore_color=color;
  190.   xv_set(message2,"Color");
  191. }
  192.  
  193. void Options(Xv_opaque obj)
  194. {
  195.   /* Notify handler for menu1 */
  196.   switch (obj->v.smenu.sel_menu) {
  197.     case 1: /* close 1 */; close_window(frame1); break;
  198.     case 2: /* close 2 */; close_window(frame2); break;
  199.     case 3: /* close 3 */; close_window(frame3); break;
  200.     case 4: /* open 1 */; open_window(frame1); break;
  201.     case 5: /* open 2 */; open_window(frame2); break;
  202.     case 6: /* open 3 */; open_window(frame3); break;
  203.     case 7: /* quit */; xv_end=1; break;
  204.     case 8: /* more... */; break;
  205.     case 9: /* memory */
  206.       sprintf(buf,"Memory left: %ul\r\n",coreleft());
  207.       ttysw_output(tty1,buf);
  208.       break;
  209.   }
  210. }
  211.  
  212. void Files(Xv_opaque obj)
  213. {
  214.   /* Notify handler for menu2 */
  215.   switch (obj->v.smenu.sel_menu) {
  216.     case 1: /* load */;
  217.       if (notice("Load a new drawing?")) ttysw_output(tty1,"Load not implemented\r\n"); break;
  218.     case 2: /* save */;
  219.       if (notice("Save the drawing?")) ttysw_output(tty1,"Save not implemented\r\n"); break;
  220.     case 3: /* more */ break;
  221.     case 4: /* clear */
  222.       if (notice("Clear the drawing?")) {
  223.         ClearPainting();
  224.         ReDraw(canvas1);
  225.       }
  226.   }
  227. }
  228.  
  229. void ListEvents(Xv_opaque obj)
  230. {
  231.   /* Event handler for button7 and message2 */
  232.   sprintf(buf,"Event: %d",ie_code);
  233.   xv_set(message2,buf);
  234. }
  235.  
  236. void main()
  237. {
  238.   /* Inicialization */
  239.   use_palette=1;
  240.   ClearPainting();
  241.   xv_init(0,0);
  242.   /* Menu creation */
  243.   /* Menu for frame1, frame2, and frame3 */
  244.   /* Submenu for item 8 of menu1 */
  245.   /* Submenu for item 3 of menu2 */
  246.   menu1=xv_create(menu);
  247.     strcpy(menu1->xv_label,"menu");
  248.     item_create("close 1");
  249.     item_create("close 2");
  250.     item_create("close 3");
  251.     item_create("open 1");
  252.     item_create("open 2");
  253.     item_create("open 3");
  254.     item_create("quit");
  255.     item_create("more...");
  256.     item_create("memory");
  257.     /* Just for demonstration. Recursive menus can damage the screen */
  258.     menu1->v.smenu.item_submenu[7]=menu1;
  259.     menu1->v.smenu.sel_menu=1;
  260.     menu1->notify_handler=(xv_handler)Options;
  261.   /* Menu for canvas1 */
  262.   menu2=xv_create(menu);
  263.     strcpy(menu2->xv_label,"options");
  264.     item_create("load");
  265.     item_create("save");
  266.     item_create("more");
  267.     item_create("clear");
  268.     menu2->v.smenu.item_submenu[2]=menu1;
  269.     menu2->notify_handler=(xv_handler)Files;
  270.   /* Interface objects creation */
  271.   frame1=xv_create(frame);
  272.     strcpy(frame1->xv_label,"XView-PC test program");
  273.     frame1->dx=218;
  274.     frame1->dy=162;
  275.     frame1->v.sframe.dxmin=218;
  276.     frame1->v.sframe.dymin=162;
  277.     frame1->menu_name=menu1;
  278.     frame1->v.sframe.adjust_exit=0;
  279.   tty1=xv_create(tty);
  280.     tty1->v.scanvas.can_yext=0; tty1->dy=42;
  281.   button1=xv_create(button);
  282.     strcpy(button1->xv_label,"popup 2..");
  283.     button1->y=46;
  284.     button1->notify_handler=(xv_handler)Open1;
  285.   button2=xv_create(button);
  286.     strcpy(button2->xv_label,"popup 3..");
  287.     button2->y=61;
  288.     button2->notify_handler=(xv_handler)Open2;
  289.   button3=xv_create(button);
  290.     strcpy(button3->xv_label,"quit");
  291.     button3->y=76;
  292.     button3->notify_handler=(xv_handler)Quit;
  293.   button4=xv_create(button);
  294.     strcpy(button4->xv_label,"xview.bmp");
  295.     button4->x=80;
  296.     button4->y=46;
  297.     button4->v.sbutton.icon_label=1;
  298.     button4->notify_handler=(xv_handler)Icon1;
  299.   button5=xv_create(button);
  300.     strcpy(button5->xv_label,"brasil.bmp");
  301.     button5->x=126;
  302.     button5->y=46;
  303.     button5->v.sbutton.icon_label=1;
  304.     button5->notify_handler=(xv_handler)Icon2;
  305.   text2=xv_create(textfield);
  306.     strcpy(text2->xv_label,"Text:");
  307.     text2->y=91;
  308.     text2->notify_handler=(xv_handler)EnterText;
  309.   text3=xv_create(textfield);
  310.     strcpy(text3->xv_label,"Integer:");
  311.     text3->y=106;
  312.     text3->v.stextfield.value_length=17;
  313.     text3->v.stextfield.field_type=int_field;
  314.     text3->notify_handler=(xv_handler)EnterInt;
  315.   text4=xv_create(textfield);
  316.     strcpy(text4->xv_label,"Real:");
  317.     text4->y=121;
  318.     text4->v.stextfield.field_type=real_field;
  319.     text4->notify_handler=(xv_handler)EnterReal;
  320.   button6=xv_create(button);
  321.     strcpy(button6->xv_label,"email.bmp");
  322.     button6->x=171;
  323.     button6->y=46;
  324.     button6->v.sbutton.icon_label=1;
  325.     button6->notify_handler=(xv_handler)Icon3;
  326.   frame2=xv_create(frame);
  327.     strcpy(frame2->xv_label,"Window 2");
  328.     frame2->x=18;
  329.     frame2->y=20;
  330.     frame2->dx=PWIDTH*5+1+2*mrgx;
  331.     frame2->dy=PHEIGHT*5+16+mrgx+mrgy;
  332.     frame2->notify_handler=(xv_handler)Close2;
  333.     frame2->menu_name=menu1;
  334.     frame2->v.sframe.dxmin=PWIDTH+1+2*mrgx;
  335.     frame2->v.sframe.dymin=PWIDTH+16+mrgx+mrgy;
  336.   canvas1=xv_create(canvas);
  337.     canvas1->y=15;
  338.     canvas1->event_handler=(xv_handler)Draw;
  339.     canvas1->notify_handler=(xv_handler)ReDraw;
  340.     canvas1->menu_name=menu2;
  341.   message1=xv_create(message);
  342.     strcpy(message1->xv_label,"x: y:");
  343.   frame3=xv_create(frame);
  344.     strcpy(frame3->xv_label,"Window 3");
  345.     frame3->x=39;
  346.     frame3->y=42;
  347.     frame3->dx=277;
  348.     frame3->dy=70;
  349.     frame3->v.sframe.dymin=30;
  350.     frame3->notify_handler=(xv_handler)Close2;
  351.     frame3->menu_name=menu1;
  352.   setting1=xv_create(setting);
  353.     strcpy(setting1->xv_label,"color #");
  354.     item_create("0");
  355.     item_create("1");
  356.     item_create("2");
  357.     item_create("3");
  358.     item_create("4");
  359.     item_create("5");
  360.     item_create("6");
  361.     item_create("7");
  362.     item_create("8");
  363.     item_create("9");
  364.     item_create("A");
  365.     item_create("B");
  366.     item_create("C");
  367.     item_create("D");
  368.     item_create("E");
  369.     item_create("F");
  370.     setting1->v.ssetting.exclusive=1;
  371.     setting1->v.ssetting.sel_setting=1;
  372.     setting1->notify_handler=(xv_handler)ChangeColor;
  373.   setting2=xv_create(setting);
  374.     strcpy(setting2->xv_label,"binary ");
  375.     setting2->y=15;
  376.     item_create("1");
  377.     item_create("2");
  378.     item_create("4");
  379.     item_create("8");
  380.   setting2->notify_handler=(xv_handler)ChangeColor;
  381.   button7=xv_create(button);
  382.     strcpy(button7->xv_label,"test events");
  383.     button7->y=30;
  384.     button7->event_handler=(xv_handler)ListEvents;
  385.   message2=xv_create(message);
  386.     message2->y=30;
  387.     message2->x=100;
  388.     message2->event_handler=(xv_handler)ListEvents;
  389.   xv_main_loop(frame1);
  390.   /* Exit */
  391.   restorecrtmode();
  392. }
  393.